<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title></title>
	<link rel="stylesheet" href="">
	<style>
		.mesg{
			width: 300px;
			padding: 10px 50px;
			background-color: pink;
		}
	</style>
</head>
<body>
<script src="https://cdn.bootcss.com/vue/2.5.8/vue.js"></script>
<div id="root">
	<p>{{VueMsg}}</p>
	<chat-room></chat-room>
</div>
<script>
	Vue.component('chat-room',{
		data : function(){
			return {
				chatList : [],
			};
		},
		methods : {
			recvFromFatherSonMsg(sonMsg){
				this.chatList.push(sonMsg);
			}
		},
		template : `
			<div>
				<h1>这是一个假的聊天室</h1>
				<div class='mesg'>
					<ul>
						<li v-for="item in chatList">{{item}}</li>
					</ul>
				</div>
				<hr />
				<user-component userName="Joe" @currentEvent="recvFromFatherSonMsg"></user-component>
				<user-component userName="Ken" @currentEvent='recvFromFatherSonMsg'></user-component>
			</div>
		`,
	});
	Vue.component('user-component',{
		props : ['userName'],
		data : function(){
			return {
				userInput : '',
			};
		},
		methods : {
			sendFatherMsg(){
				if(!this.userInput)return ;
				this.$emit('currentEvent',this.userInput);
				this.userInput = '';
			},
		},
		template : `
			<p>
				<label >{{userName}}</label>
				<input type="text" v-model="userInput" />
				<button @click="sendFatherMsg">发送</button>
			</p>
		`,
	});
	var vm = new Vue({
		el : '#root',
		data : {
			VueMsg : "Hello VueJs !",
		}
	})
</script>
<script>
	
</script>	
</body>
</html>